package cn.jinjimi.app.main.widget.biz;

import android.content.Context;
import android.net.Uri;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import cn.jinjimi.app.R;
import cn.jinjimi.app.main.widget.ToolBar.WebToolbar;


/**
 * Created by Rain on 2015/12/21.
 */
public class MenuConponentView extends LinearLayout {

    public MenuConponentView(final Context context, final WebToolbar.ToolbarAction action) {
        super(context);

        this.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        this.setOrientation(VERTICAL);
        this.setDividerDrawable(ContextCompat.getDrawable(context, R.drawable.shape_divider_line));
        this.setShowDividers(SHOW_DIVIDER_MIDDLE);

        //入口
        final View item = LayoutInflater.from(context).inflate(R.layout.layout_menu_item, null);

        //设置label、拿到图标后设置图标
        ImageView ivIcon = (ImageView) item.findViewById(R.id.iv_item);
        TextView tvLabel = (TextView) item.findViewById(R.id.tv_label);

        if (action.type == WebToolbar.ToolbarAction.TYPE_IMAGE) {
            ivIcon.setImageURI(Uri.parse(((WebToolbar.ToolbarActionImage) action).imgUrl));
        } else if (action.icon != null) {
            ivIcon.setImageDrawable(action.icon);
        }

        tvLabel.setText(action.label);

        //这里可以设置上边距
        this.addView(item);
    }

}
